package com.ctgu.demo03.controller;

import com.ctgu.demo03.service.ProductsService;
import com.ctgu.demo03.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @ClassName ProductsControllers
 * @Author Alex2
 * @Date 2025/3/11 21:53
 **/
@RestController
@RequestMapping("/api/products")
public class ProductsController {

    @Autowired
    private ProductsService productsService;

    /**
     * @Author: Alex
     * @Description: 插入产品
     */
    // http://localhost:8080/api/products/insertProducts?name=Drill&stock=100
    @GetMapping("/insertProducts")
    public ApiResult insertProducts(@RequestParam("name") String name,@RequestParam("stock") Integer stock) {
        return productsService.insertProducts(name, stock);
    }

    /**
     * @Author: Alex
     * @Description: 版本号实现乐观锁
     */
    // http://localhost:8080/api/products/updateProductPrice?id=1
    @GetMapping("/updateProductPrice")
    public ApiResult updateProductPrice(@RequestParam("id") Integer id) {
        return productsService.updateProductPrice(id);
    }
}
